package com.newmuis.open.codeeval.easy;

/**
 * CodeEval.com > Easy Challenges > Multiplication Tables
 * 
 * Description:
 * 
 * Print out the grade school multiplication table upto 12*12.
 * 
 * Input sample:
 * 
 * None
 * 
 * Output sample:
 * 
 * Print out the table in a matrix like fashion, each number formatted to a width of 4 (The numbers
 * are right-aligned and strip out leadeing/trailing spaces on each line). The first 3 line will
 * look like:
 * e.g.
 * 
 * 1 2 3 4 5 6 7 8 9 10 11 12
 * 2 4 6 8 10 12 14 16 18 20 22 24
 * 3 6 9 12 15 18 21 24 27 30 33 36
 * 
 * @author Jonathan Newmuis (jon@newmuis.com)
 * @category easy
 * 
 */
public class tables {
	/**
	 * @param args No arguments should be specified. Any specified arguments are ignored.
	 */
	public static void main(final String[] args) {
		final StringBuilder tableBuilder = new StringBuilder();
		for (int row = 1; row <= 12; row++) {
			for (int col = 1; col <= 12; col++) {
				// Calculate the entry for the current cell.
				final String currentValue = Integer.toString(col * row);

				// Left-pad the number with spaces to right-align it.
				final int padding = 4 - currentValue.length();
				for (int i = 0; i < padding; i++) {
					tableBuilder.append(" ");
				}

				// Append the entry for the current cell to the output.
				tableBuilder.append(currentValue);
			}
			tableBuilder.append("\n");
		}

		System.out.println(tableBuilder.toString());
	}
}
